home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK1.toast / Development Kits (Disc 1) / Apple Shared Library Manager / ASLM Examples / Example Tools / Sources / TPrioritySchedulerExample.cp < prev    next >
Encoding:
Text File  |  1996-11-19  |  2.5 KB  |  80 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        TPrioritySchedulerExample.cp
  3.  
  4.     Contains:    This module shows an example of the TPriorityScheduler class.
  5.  
  6.     Copyright:    © 1993 by Apple Computer, Inc., all rights reserved.
  7.  
  8. */
  9.  
  10. #include "TInitSLM.h"            // the TInitSLM class and SLM include files
  11. #include "TSchedulerExample.h"
  12.  
  13. ///————————————————————————————————————————————————————————————————————————————————————
  14. ///    CONSTANTS
  15. ///————————————————————————————————————————————————————————————————————————————————————
  16.  
  17. const unsigned  kNumofStudents = 8;            //     no. of students                            
  18.  
  19.  
  20. ///————————————————————————————————————————————————————————————————————————————————————
  21. ///    GLOBALS
  22. ///————————————————————————————————————————————————————————————————————————————————————
  23.  
  24. // array of student names
  25. char    *gStudents[kNumofStudents] ={"John Sculley",
  26.                                      "Jane Doe    ", 
  27.                                      "Bill Clinton",
  28.                                      "George Bush ", 
  29.                                      "Mick Jagger ", 
  30.                                      "Ren & Stimpy",
  31.                                      "Joe Montana ", 
  32.                                      "Al Einstein "};
  33.  
  34. // grades for the above students
  35. Grade    gGrades[kNumofStudents]       ={kB, kA, kC, kF, kA, kD, kB, kB};
  36.  
  37. /*————————————————————————————————————————————————————————————————————————————————————
  38.     main 
  39.     
  40.     This example schedules a list of student to be displayed depending to their grades.
  41.     First it creates a TPriorityScheduler, then for each students it schedules a
  42.     TReport operation. This operation. once invoked, displays the students name and
  43.     his/her grade. The operations are executed in order of priority with the priority
  44.     being based on the student's grade.
  45. ————————————————————————————————————————————————————————————————————————————————————*/
  46.  
  47. main() 
  48. {    
  49.     TInitSLM initLibraryManager;            // initialize the shared library manager
  50.     
  51.     if( initLibraryManager.Failed() )        // If we failed, let go home
  52.         return 1;
  53.  
  54.     TReport                *thereport[kNumofStudents];
  55.     TPriorityScheduler     *reportScheduler;
  56.     
  57.     reportScheduler = new TPriorityScheduler;// create our priority Scheduler
  58.     
  59.     // for each student schedule a TOperation to report the grade
  60.     for( short i=0; i<kNumofStudents; i++ ) {
  61.         thereport[i] = new TReport;
  62.         thereport[i]->NewStudent( gStudents[i] );
  63.         thereport[i]->SetGrade( gGrades[i] );
  64.                                             
  65.         // now setup the priority for this operation 
  66.         thereport[i]->SetPriority( gGrades[i]+kNormalPriority );
  67.         
  68.         reportScheduler->Schedule( thereport[i] );
  69.     }
  70.     
  71.     cout<< "Report cards prioritized depending on student's grade\n" << endl;
  72.         
  73.     reportScheduler->Run();            // process all the operations
  74.  
  75.     delete reportScheduler;            // by now we should be done
  76.         
  77.     return 0;
  78. }
  79.  
  80.